package www.openteam.com.model.business;

import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.InsertStatus;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * Created by kylin on 2016/10/20.
 */

public class UpdateCustomInfoModel extends BaseModel {


    private boolean isUpdate = false;

    public boolean updateCustomInfo(String code, String name,
                                    String type, String paytime,
                                    String moneytype, String SendAddress,
                                    String connecter, String BusinessMan,
                                    String CreditNumb, String cTel, int id, final UpdateCustomInfoOnListener updateCustomInfoOnListener) {

        httpApiService.updateCustomInfo(code, name, type, paytime, moneytype,
                SendAddress, connecter, BusinessMan, CreditNumb, cTel, id)
                .compose(new CommonTransformer<InsertStatus>())
                .subscribe(new CommonSubscriber<InsertStatus>(OTApplication.getmContext()) {
                    @Override
                    public void onNext(InsertStatus insertStatus) {
                        isUpdate = true;
                        updateCustomInfoOnListener.updateCISuccess(insertStatus);

                    }

                    @Override
                    protected void onError(ApiException e) {
                        super.onError(e);
                        isUpdate = false;
                        updateCustomInfoOnListener.updateCIFail(e);
                    }
                });

        return isUpdate;
    }


    public interface UpdateCustomInfoOnListener {
        void updateCISuccess(InsertStatus insertStatus);

        void updateCIFail(Throwable throwable);

    }
}
